package cn.bdqn.config;

import cn.bdqn.intercepter.MyIntercepter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Bean
    public InternalResourceViewResolver getViewResolver() {
       return new InternalResourceViewResolver("/WEB-INF/jsp/",".jsp");
    }
// 解决静态资源加载问题，等价于<mvc:default-servlet-handler/>
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController("/").setViewName("aaa");
        registry.addRedirectViewController("/","index1.jsp");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyIntercepter());
    }
}
